package stu.day19_day24.day24;

import java.util.Arrays;
import java.util.Scanner;

public class hw1 {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int number = Integer.parseInt(sc.nextLine());
        int days = Integer.parseInt(sc.nextLine());

        int[] item = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();

        int[][] arr = new int[number][days];
        for(int i=0;i<number;i++){
            String[] str = sc.nextLine().split(" ");
            for(int j=0;j<days;j++){
                arr[i][j] = Integer.parseInt(str[j]);
            }
        }

        int[] maxNum = new int[number];
        for(int i=0;i<number;i++){
            int num = 0;
            for(int j=1;j<days;j++){
                if((arr[i][j]-arr[i][j-1])>0){
                    num += arr[i][j]-arr[i][j-1];
                }
            }
            maxNum[i] = num;
        }

        int allNum = 0;
        for(int i=0;i<number;i++){
            allNum += maxNum[i]*item[i];
        }

        System.out.println(allNum);
    }

}
